/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package edu.uts.reekie.designer.execution.edit;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import edu.uts.reekie.designer.edit.EditPartFactoryBase;
import edu.uts.reekie.designer.edit.ViewDiagramEditPart;
import edu.uts.reekie.designer.execution.figures.ConcreteFigureFactory;
import edu.uts.reekie.designer.execution.model.*;
import edu.uts.reekie.designer.figures.*;
import edu.uts.reekie.designer.model.*;


public class ViewPartFactory
	extends EditPartFactoryBase
{

public EditPart createEditPart(EditPart context, Object model) {
	EditPart ep = null;
	
	
	ModelFactory mf = createModelFactory();
	FigureFactory ff = createFigureFactory();
	
	if (model instanceof Connector)
		ep = new ConnectorEditPart();
	
	else if (model instanceof ViewComponent)
		ep = new ViewComponentEditPart(mf,ff);
	
	else if (model instanceof ViewExternalInterface)
		ep = new ViewExternalInterfaceEditPart(mf,ff);
	
	//Note that subclasses of ViewDiagram have already been matched above, like Circuit
	else if (model instanceof ViewDiagram)
		ep = new ViewDiagramEditPart(mf,ff);
	
	else if (model instanceof PassiveComponent)
		ep = new PassiveComponentEditPart(mf,ff);
	
	
	if (ep!=null) {
		ep.setModel(model);
		return ep;
	} else {
		return super.createEditPart(context, model);
	}
	
}

@Override
protected FigureFactory createFigureFactory() {
	return new ConcreteFigureFactory();
}

@Override
protected ModelFactory createModelFactory() {
 
	return new ConcreteModelFactory();
}

}
